package com.example.demo.controller;

import com.example.demo.domain.Ebook;
import com.example.demo.req.EbookQueryReq;
import com.example.demo.req.EbookSaveReq;
import com.example.demo.resp.CommonResp;
import com.example.demo.resp.PageResp;
import com.example.demo.services.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController //这是返回接口
@RequestMapping("/ebook")
public class EbookController {

    @Resource
    private EbookService ebookService;

    @GetMapping("/list")
    public CommonResp<PageResp<Ebook>> list(@Valid EbookQueryReq req){
        CommonResp<PageResp<Ebook>> resp= new CommonResp<>();
        PageResp<Ebook> list = ebookService.list(req);
        resp.setData(list);
        return  resp;
    }

    @GetMapping("/getDetail")
    public CommonResp<Ebook> getDetail(@Valid EbookQueryReq req){
        CommonResp<Ebook> resp= new CommonResp<>();
        Ebook ebook = ebookService.getDetail(req);
        resp.setData(ebook);
        return  resp;
    }

    @PostMapping("/save")
    public CommonResp<PageResp<Ebook>> save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp= new CommonResp<>();
        ebookService.save(req);
        return  resp;
    }

    @GetMapping("/delete")
    public CommonResp<PageResp<Ebook>> delete(EbookSaveReq req){
        CommonResp resp= new CommonResp<>();
        ebookService.delete(req);
        return  resp;
    }
}
